package cn.gailvlun.gll.presentation.charge.vm

import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.ViewModel
import cn.gailvlun.gll.config.failed
import cn.gailvlun.gll.config.loading
import cn.gailvlun.gll.config.success
import cn.gailvlun.gll.net.HttpMethods
import cn.gailvlun.gll.net.HttpSubscriber
import cn.gailvlun.gll.net.pay.GetBalanceRes
import cn.gailvlun.gll.presentation.charge.model.Outcome
import cn.gailvlun.gll.util.RxUtil

class ChargeViewModel: ViewModel {
    public var balanceOutcome = MutableLiveData<Outcome<GetBalanceRes>>()

    constructor() : super() {

    }

    fun loadBalance() {
        balanceOutcome.loading(true)
        HttpMethods.getPayService()
                .balance
                .compose(RxUtil.applyScheduler())
                .subscribe(object: HttpSubscriber<GetBalanceRes>() {
                    override fun onSuccess(response: GetBalanceRes) {
                        balanceOutcome.success(response)
                    }

                    override fun onFailure(errMsg: String, response: GetBalanceRes?, code: Int) {
                        balanceOutcome.failed(errMsg)
                    }
                })
    }
}